package fr.umlv.m2.uwp2011.service.user;

import java.io.Serializable;

@SuppressWarnings("serial")
public class UserDTO implements Serializable {
	/**
	 * 
	 */
	public static final int STUDENT = 0;
	public static final int TEACHER = 1;
	public static final int SECRETARY = 2;
	//public static final int ADMIN = 3;

	private String login;
	private String password;
	private String givenName;
	private String lastName;
	private String mail;
	private int group; 

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getGivenName() {
		return givenName;
	}

	public void setGivenName(String givenName) {
		this.givenName = givenName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getLastName() {
		return lastName;
	}

	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}
	
	public boolean isStudent() {
		return group == STUDENT;
	}
	
	public boolean isTeacher() {
		return group == TEACHER;
	}
	
	public boolean isSecretary() {
		return group == SECRETARY;
	}
//	public boolean isAdmin() {
//		return isAdmin;
//	}
//	
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(login+"\n");
		sb.append(password+"\n");
		sb.append(givenName+"\n");
		sb.append(lastName+"\n");
		sb.append(mail+"\n");
		String group = null;
		
		if(this.group == STUDENT) {
			group = "Student";
		}
		else if(this.group == TEACHER) {
			group = "teacher";
		}
		else if(this.group == SECRETARY) {
			group = "admin";
		}
		sb.append(group+"\n");
		return sb.toString();
	}
	

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}UserDTO userDTO = (UserDTO) obj;
		if (!userDTO.givenName.equals(this.givenName)){
			return false;
		}if (!userDTO.password.equals(this.password)){
			return false;
		}if (!userDTO.lastName.equals(this.lastName)){
			return false;
		}if (!userDTO.login.equals(this.login)){
			return false;
		}if (!userDTO.mail.equals(this.mail)){
			return false;
		}if (userDTO.group != this.group){
			return false;
		}
		return true;
	}

	public void setGroup(int group) {
		this.group = group;
	}

	public int getGroup() {
		return group;
	}
}
